package com.gton.service;

import com.gton.io.RPCCommonRequest;
import com.gton.io.Resp;
import com.gton.util.ContextCommonMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @description: 调取userManagerService
 * @author: GuoTong
 * @createTime: 2022-09-24 16:05
 * @since JDK 1.8 OR 11
 **/

@Service
@Slf4j
public class GotoThirdSysRouterService {

    @Autowired
    private RestTemplate restTemplate;

    public Resp getThirdSysRouterService_Hello() {
        // rest基于Nacos的远程调用
        ResponseEntity<Resp> remoteCallBackEntity = restTemplate.
                getForEntity("http://third-sys-router/outSys_rest_to_this",
                        Resp.class);

        HttpStatus statusCode = remoteCallBackEntity.getStatusCode();
        if (statusCode.isError()) {
            log.info("error state : " + remoteCallBackEntity.getStatusCodeValue());
            return Resp.error(ContextCommonMsg.FILE_CONNECTION_MSG, ContextCommonMsg.FILE_CONNECTION_CODE);
        }
        Resp callBackBody = remoteCallBackEntity.getBody();
        if (Objects.isNull(callBackBody)) {
            log.info("userId is error ");
            return Resp.error(null);
        }
        Object data = callBackBody.getData();
        return Resp.Ok(data);
    }

    public Resp createMapData(RPCCommonRequest rpcCommonParam) {
        return Resp.Ok(rpcCommonParam);
    }
}
